package map.android.baidu.carpool.utils;

import java.lang.ref.WeakReference;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.webkit.WebView;

import com.baidu.components.api.extra.APIProxy;

public class CommonWebViewProtocol {

	public static boolean checkExtendRedirect(WeakReference<Activity> ref, WebView webview, String url) {
		if (webview == null || TextUtils.isEmpty(url))
			return false;
		Context context = webview.getContext();
		try {

			String data = url.substring(url.indexOf(":") + 1);
			if (url.startsWith("tel:")) {
				TelephonyManager telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
				if (telMgr.getSimState() == TelephonyManager.SIM_STATE_READY) {
					APIProxy.sys().dial(data);
				} else {
					ToastForCarpool.show(context, "当前电话功能不可用！");
				}
				return true;
			}
		} catch (ActivityNotFoundException e) {
			e.printStackTrace();
		}

		return false;
	}

}
